// pages/msgAnswer/msgAnswer.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    question: {},
    comment:{},
    fileInfo:{},
    //问题id
    qes_id: null, //页面跳转时获得

    followHidden:true,

  },
  
  onLoad:function(options){
    console.log(options)
    var that=this
    wx.request({
      url: 'https://www.cerywxr.com/treehole/index.php/Home/sharing/get_msg_answer',
      method: "POST", //请求方式,
      header: {
        'content-type': 'application/x-www-form-urlencoded' //POST提交数据方式
      },
      data: {
        qes_id: options.qes_id,
        file_id:options.file_id,
        comment_id:options.comment_id,
        have_read: options.have_read,
        msg_id:options.msg_id,
      },
      success(res){
        console.log(res.data)
        if(options.follow=='1'){
          that.setData({
            followHidden:false,
          })
        }
        that.setData({
          qes_id: options.qes_id,
          question: res.data.question,
          comment:res.data.comment,
          fileInfo:res.data.fileInfo,

        })
        if(res.data.error_code!=0){
          
        }
      }
    })
  },

  //评论点赞
  zan(e) {
    var that = this
    wx.request({
      url: 'https://www.cerywxr.com/treehole/index.php/Home/sharing/comment_like',
      method: "POST", //请求方式,
      header: {
        'content-type': 'application/x-www-form-urlencoded' //POST提交数据方式
      },
      data: {
        id: that.data.comment.id,
        zan: that.data.comment.zan,
        like_num: that.data.comment.like_num,
      },
      success(res) {
        console.log(res.data)
        var zan = that.data.comment.zan
        console.log(zan)
        //改变对象数组某一下标的对象值
        var change1 = "comment.zan"
        var change2 = "comment.like_num"
        if (zan) {
          wx.showToast({
            title: '点赞成功',
            icon: 'success',
            success() {
              that.setData({
                [change1]: !zan,
                [change2]: parseInt(that.data.comment.like_num) + 1
              })
            }
          })
        } else {
          wx.showToast({
            title: '取消成功',
            icon: 'success',
            success() {
              that.setData({
                [change1]: !zan,
                [change2]: parseInt(that.data.comment.like_num) - 1
              })
            }
          })
        }
      }
    })
  },

})